

USE [T2Logging]
GO

-----------------------------------------------------------
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_dbo_Tenant_dbo_Application]') AND parent_object_id = OBJECT_ID(N'[dbo].[Application]'))
ALTER TABLE [dbo].[Application] DROP CONSTRAINT [fk_dbo_Tenant_dbo_Application]
GO
ALTER TABLE [dbo].[Application]  WITH CHECK ADD  CONSTRAINT [fk_dbo_Tenant_dbo_Application] FOREIGN KEY([TenantID])
REFERENCES [dbo].[Tenant]([TenantID])
GO
ALTER TABLE [dbo].[Application] CHECK CONSTRAINT [fk_dbo_Tenant_dbo_Application]
GO


-----------------------------------------------------------
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_dbo_Application_dbo_Log]') AND parent_object_id = OBJECT_ID(N'[dbo].[Log]'))
ALTER TABLE [dbo].[Log] DROP CONSTRAINT [fk_dbo_Application_dbo_Log]
GO
ALTER TABLE [dbo].[Log]  WITH CHECK ADD  CONSTRAINT [fk_dbo_Application_dbo_Log] FOREIGN KEY([ApplicationID])
REFERENCES [dbo].[Application]([ApplicationID])
GO
ALTER TABLE [dbo].[Log] CHECK CONSTRAINT [fk_dbo_Application_dbo_Log]
GO


-----------------------------------------------------------
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_dbo_LogCategory_dbo_Log]') AND parent_object_id = OBJECT_ID(N'[dbo].[Log]'))
ALTER TABLE [dbo].[Log] DROP CONSTRAINT [fk_dbo_LogCategory_dbo_Log]
GO
ALTER TABLE [dbo].[Log]  WITH CHECK ADD  CONSTRAINT [fk_dbo_LogCategory_dbo_Log] FOREIGN KEY([LogCategoryID])
REFERENCES [dbo].[LogCategory]([LogCategoryID])
GO
ALTER TABLE [dbo].[Log] CHECK CONSTRAINT [fk_dbo_LogCategory_dbo_Log]
GO



